// 
import http from '@/components/firstui/fui-request'
import tost from './fui-app.js'

//初始化请求配置项
http.create({
	host: 'http://192.168.31.85:18080/admin-api',
	header: {}
})
//请求拦截
http.interceptors.request.use(config => {
	//请求之前可在请求头中加入token等信息
	let accessToken = uni.getStorageSync('accessToken');
	if (accessToken) {
		config.header = {
			'Authorization': "Bearer " + accessToken.accessToken,
			'tenant-id': accessToken.tenantId,
		}
	}
	return config
})
//响应拦截
http.interceptors.response.use(response => {
	//TODO
	if (response.code == 0) {
		tost.toast('请求成功！')
		return response.data
	} else{
		return Promise.reject('接口返回失败！')
	}
}, (err) => {
	//错误响应：断网、错误域名等
	return Promise.reject(err)
})

export default http